home *** CD-ROM | disk | FTP | other *** search
- #-------------------------------------------------------------------------------
- # UtoL
- # MPW Shell Script
- # Written by Gina Cherry • August 16, 1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage:
- # UtoL [Window]
- #
- # Function:
- # UtoL converts the selected text in the specified window from uppercase to lowercase.
- #
- # Note: To add this command to the Edit menu, add the following line to your UserStartup file:
- # AddMenu Edit 'UtoL/5' 'UtoL "{Active}"'
- #-------------------------------------------------------------------------------
-
- # Make sure there is no more than 1 parameter.
- If {#} > 1
- Echo "###Usage: {0} window" >> Dev:StdErr
- Exit 1
- End
-
- # Do not exit on error.
- Set Exit 0
-
- # Initialize flag variable.
- Set Flag 0
-
- # Set Window to the parameter, or to the target window if no parameter was given.
- If {#} == 1
- Set Window "{1}"
- Else
- Set Window "{Target}"
- End
-
- # Set the variable Old to the selected text in the input file. This command has the side effect of
- # checking whether the window is open. Catenate will fail if Window is not an open window. The
- # variable flag will be set to 1 if and only if the Catenate command is not successful.
- Begin
- Set Old "`catenate "{Window}.§" ≥ Dev:Null || Set Flag 1`"
- End ≥ Dev:Null
-
- # Check if flag variable is set; if it is, write error message and exit with status 2.
- If {Flag} == 1
- Echo "### {0}: {Window} is not a valid window" >> Dev: StdErr
- Exit 2
- End
-
- # If Old is the null string, no text was selected, so do nothing, and exit.
- Exit If "{old}" == ""
-
- # Otherwise, do the conversion.
- # Save the value of NewWindowRect to restore later.
- Set OldWindowRect NewWindowRect
-
- # Set NewWindowRect so that new windows are small.
- Set NewWindowRect 0,0,100,100
-
- # Open a Temporary workspace.
- Open -n {0}.Temp
-
- # Restore old value of NewWindowRect.
- Set NewWindowRect OldWindowRect
-
- # Translate all uppercase letters in the selected text to lowercase, and redirect the output to the
- # temporary file.
- Translate A-Z a-z < "{Window}.§" > {0}.Temp
-
- # Select the entire temporary file.
- Find •:∞ {0}.Temp
-
- # Copy selection to the clipboard.
- Copy § {0}.Temp
-
- # Paste the converted text to Window, overwriting the old version of the text.
- Paste § "{Window}"
-
- # Close the workspace; don't save changes.
- Close -n {0}.Temp